package com.beecloud.microservice.user.web;

import com.beecloud.microservice.user.domain.error.ParameterWrongException;
import com.beecloud.microservice.user.domain.error.ResourceNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@ControllerAdvice
public class CustomerError {
    @ExceptionHandler(value = {ParameterWrongException.class})
    void handleBadRequests(HttpServletResponse response) throws IOException {
        response.sendError(HttpStatus.BAD_REQUEST.value());
    }

    @ExceptionHandler(value = {ResourceNotFoundException.class})
    void handleNotFoundRequest(HttpServletResponse response) throws IOException {
        response.sendError(HttpStatus.NOT_FOUND.value());
    }
}
